package com.sunwayworld.basemodule.rm.person.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.sunwayworld.framework.at.annotation.AuditTrailType;
import com.sunwayworld.framework.at.annotation.AuditTrailEntry;
import com.sunwayworld.framework.spring.annotation.GikamBean;

import com.sunwayworld.basemodule.rm.person.dao.LimsPersonCertificateDao;
import com.sunwayworld.basemodule.rm.person.bean.LimsPersonCertificateBean;
import com.sunwayworld.basemodule.rm.person.service.LimsPersonCertificateService;
import com.sunwayworld.framework.context.ApplicationContextHelper;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;

@Repository
@GikamBean
public class LimsPersonCertificateServiceImpl implements LimsPersonCertificateService {

    @Autowired
    private LimsPersonCertificateDao limsPersonCertificateDao;

    @Override
    @SuppressWarnings("unchecked")
    public LimsPersonCertificateDao getDao() {
        return limsPersonCertificateDao;
    }

    @Transactional
    @AuditTrailEntry(AuditTrailType.INSERT)
    @Override
    public Long insert(RestJsonWrapperBean wrapper) {
        LimsPersonCertificateBean insertBean = wrapper.parseUnique(LimsPersonCertificateBean.class);
        Integer sorter = getDao().selectMaxSorted(insertBean.getPersonId()) + 1;
        Long id = ApplicationContextHelper.getNextSequenceNumber(getDao().getTable());
        insertBean.setSorter(sorter);
        insertBean.setId(id);
        getDao().insert(insertBean);
        return id;
    }

}
